<%@ page import="com.qq.model.User" %>
<%@ page import="java.net.URLEncoder" %>
<%@ page import="java.sql.*" %>
<%@ page import="com.qq.util.DBUtil" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    //接收表单信息
    String name = request.getParameter("name");
    String password =  request.getParameter("password");

    out.print(name);
    out.print(password);

    //Class.forName("com.mysql.jdbc.Driver");
  //  Connection con = DriverManager.getConnection(
       //     "jdbc:mysql://127.0.0.1:3306/library?serverTimezone=Hongkong&useSSL=false&characterEncoding=utf-8&useUnicode=true&user=root&password=123456");
   //调用
    //将这里注解
  Connection con  = DBUtil.getConnection();
   PreparedStatement pstmt = con.prepareStatement("select * from user where name =? and password=?");
   pstmt.setString(1,name);
   pstmt.setString(2,password);
   ResultSet rs = pstmt.executeQuery();
    
   //  Statement stmt = con.createStatement();
  //  ResultSet rs = stmt.executeQuery("SELECT * FROM user WHERE name='" + name + "' And password='" + password+"'");

    //和数据库进行核对。
    //成功：重定向到“个人中心”
    //失败：重定向回 登录页
    if(rs.next()){
        User user = new User(name,password);
        session.setAttribute("USER",user);
        response.sendRedirect("center/home.jsp");
    }else{
        String message ="你输入的账号密码有误";
        message = URLEncoder.encode(message,"utf-8");

        response.sendRedirect("form.jsp?" + "message=" + message +
                "&name="+ name + "&password="+password);
    }
%>
